<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .box{
            position: relative;
            width: 200px;
            height: 200px;
            background-color: lightblue;
        }
    </style>
</head>
<body>
    <div class="box" contenteditable></div>
    <p class="pEl">两个黄鹂鸣翠柳，一行白鹭上青天</p>

    <script>
        // 开启全局可编辑模式, 元素上键盘事件失效
        // document.designMode = 'on'
        var pEl = document.querySelector('.pEl');
        // 点击p标签让他可编辑
        pEl.onclick = function () {
            this.setAttribute('contenteditable', true)
            setTimeout(function () {
                pEl.focus()
            }, 200)
        }
        
        pEl.onkeydown = function () {
            if (event.keyCode === 13) {
                // 阻止默认事件发生
                event.returnValue = false;
                // event.preventDefault();
                this.blur()
            }
        }
        pEl.onblur = function () {
            console.log(this.innerText);
        }
    </script>
</body>
</html>